<%--
  Created by IntelliJ IDEA.
  User: yuan
  Date: 2022/11/23
  Time: 20:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>展示员工列表</title>
    <base href="<%=request.getContextPath()+"/"%>">
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<script type="text/javascript">
    function confirmDel(empno) {
        console.log("进入确认弹窗");
        let s = window.confirm("确定删除吗？");
        console.log(s);
        if (s){
            window.location.href="${pageContext.servletContext.contextPath}/EmpServlet/delete?empno="+empno;
        }

    }

    $(function () {
        $("table").find("tr").each(function (index) {
            if (index != 0){
                if (index%2===0) {
                    $(this).css("background-color","red").slideUp(2000).slideDown(2000);
                }else {
                    $(this).css("background-color","orange").slideUp(2000).slideDown(2000);
                }
            }
        });
    });
</script>
<body>
<c:if test="${msg!=null}">
    <script>alert('${msg}')</script>
    <%
        request.setAttribute("msg",null);
    %>
</c:if>
<a href="emp/addEmp.jsp">添加员工</a>

<table border="1" cellspacing="1" cellpadding="5">
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>工资</th>
        <th>奖金</th>
        <th>领导</th>
        <th>部门</th>
        <th>职位</th>
        <th>入职时间</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${empList}" var="emp" varStatus="status" >
        <tr>
            <td>${emp.empno}</td>
            <td>${emp.ename}</td>
            <td>${emp.sal}</td>
            <td>${emp.comm == null?0.0:emp.comm}</td>
            <td>${emp.mgr == null?"BOSS":emp.mgr}</td>
            <td>${emp.deptno}</td>
            <td>${emp.job}</td>
            <td>${emp.hiredate}</td>
            <td>
                <a href="${pageContext.servletContext.contextPath}/EmpServlet/selectOne?empno=${emp.empno}">编辑</a>
                <a href="javascript:void(0)" onclick="confirmDel(${emp.empno})">删除</a>
            </td>
        </tr>
    </c:forEach>

</table>
</body>
</html>
